package cn.terminus.biz.customer.customdemandarea;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.customdemandarea.dto.*;
import cn.terminus.data.customer.customdemandarea.dao.CustomDemandAreaDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomDemandArea)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:47
 */
@Component
public class CustomDemandAreaManager extends AbstractTerminusManager {
    @Autowired
    private CustomDemandAreaDao customDemandAreaDao;

    public Integer add(CustomDemandAreaNewDto dto) throws DataAccessException {
        try {
            return customDemandAreaDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomDemandAreaEditDto dto) throws DataAccessException {
        try {
            return customDemandAreaDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomDemandAreaResultDto> gets(CustomDemandAreaGetsDto dto) throws DataAccessException {
        try {
            return customDemandAreaDao.gets(dto);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomDemandAreaResultDto> query(CustomDemandAreaQueryDto dto) throws DataAccessException {
        try {
            return customDemandAreaDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomDemandAreaDeleteDto dto) throws DataAccessException {
        try {
            return customDemandAreaDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomDemandAreaResultDto> page(CustomDemandAreaQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomDemandAreaResultDto> result = (Page<CustomDemandAreaResultDto>) customDemandAreaDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomDemandAreaResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer addMulti(List<CustomDemandAreaNewDto> areaNewDtoList) throws DataAccessException {
        try {
            return customDemandAreaDao.addMulti(areaNewDtoList);
        } catch (Exception e) {
            logger.error("CustomDemandAreaManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
